"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class MBase {
    /**去除字符串两端指定字符 */
    static trimStr(str, lm = "") {
        let sps = [" "].concat(lm.split(""));
        sps = sps.map((x) => x.replace(/\\/, "\\\\"));
        sps.forEach((x) => {
            str = str.replace(new RegExp(`^${x}`, "g"), "");
            str = str.replace(new RegExp(`${x}$`, "g"), "");
        });
        return str;
    }
    /** 获取分隔后的最后一节*/
    static lastWord(text, sp = "/") {
        if (!text)
            return "";
        return text.split(sp).pop() || text;
    }
    /**设置缩进 */
    static ident(lines, count = 0) {
        count = parseInt(`${count}`) || 0;
        if (count < 0) {
            const reg = new RegExp(`^\\s{${Math.abs(count)}}`);
            return lines.map((x) => x.replace(reg, ""));
        }
        else if (count > 0) {
            const space = new Array(count).fill(" ").join("");
            return lines.map((x) => `${space}${x}`);
        }
        else {
            return lines;
        }
    }
    /**转成多行 */
    static toRows(lines) {
        return lines.join("\r\n");
    }
    /**转成类C注释 */
    static toCNote(text, ident = 0) {
        if (text instanceof Array) {
            return MBase.ident([`/**`, ...text.map((x) => ` * ${x}`), ` */`], ident);
        }
        else {
            return MBase.ident([`/** ${text} */`], ident);
        }
    }
    /**转成通用注释 */
    static toCommonNote(text, ident = 0) {
        const txt = text instanceof Array ? text : [`${text || ""}`];
        const txts = txt.map((x) => `// ${x}`);
        return MBase.ident(txts, ident);
    }
    /**转成dart注释 */
    static toDartNote(text, ident = 0) {
        const txt = text instanceof Array ? text : [`${text || ""}`];
        const txts = txt.map((x) => `/// ${x}`);
        return MBase.ident(txts, ident);
    }
    /**对象解析成字符串 */
    static parseObj(obj, sp = " ") {
        let res = [];
        for (let p in obj)
            res.push(`${p}=${obj[p]}`);
        return res.join(sp);
    }
    /**首字母大写 */
    static camelUpperCase(text) {
        return text ? `${text.charAt(0).toUpperCase()}${text.slice(1)}` : "";
    }
    /**首字母小写 */
    static camelLowercase(text) {
        return text ? `${text.charAt(0).toLowerCase()}${text.slice(1)}` : "";
    }
    /**驼峰命名法 */
    static camelCaseName(txts, lower = false) {
        if (lower) {
            const words = txts.slice(0);
            return [MBase.camelLowercase(words.shift())]
                .concat(words.map((w) => MBase.camelUpperCase(w)))
                .join("");
        }
        else {
            return txts.map((w) => MBase.camelUpperCase(w)).join("");
        }
    }
    /**蛇形命名法 */
    static snakeCaseName(txts, sp = "_") {
        return txts.map((x) => MBase.camelLowercase(x)).join(sp);
    }
    /**蛇形命名法转驼峰命名法 */
    static snakeToCamel(txt, lower = false) {
        const words = txt.split("-").map(x => x.split("_")).flat();
        return MBase.camelCaseName(words, lower);
    }
    /**驼峰命名法转蛇形命名法 */
    static camelToSnake(txt, sp = "_") {
        const words = txt.split(/(?=[A-Z])/g);
        return words.map((x) => MBase.camelLowercase(x)).join(sp);
    }
}
exports.default = MBase;
